 /********************************************************************
         file name:      MJLexer
         file ext:       flex
         author:         Mirko Francuski
         index:          225/06
 *********************************************************************/

package ppdz;
import java_cup.runtime.Symbol;

%%

%{
  // uključivanje informacije o poziciji tokena
  private Symbol new_symbol(int type) {
    return new Symbol(type, yyline+1, yycolumn);
  }
  // uključivanje informacije o poziciji tokena
  private Symbol new_symbol(int type, Object value) {
    return new Symbol(type, yyline+1, yycolumn, value);
  }
%}

%cup

  /* Exclusive state */
%xstate COMMENT

%eofval{
  return new_symbol(sym.EOF);
%eofval}

%line
%column

%%

" "    {}
"\b"   {}
"\t"   {}
"\r\n" {}
"\n"   {}
"\f"   {}

"break"  { return new_symbol(sym.BREAK);  }
"class"  { return new_symbol(sym.CLASS);  }
"else"   { return new_symbol(sym.ELSE);   }
"final"  { return new_symbol(sym.FINAL);  }
"if"     { return new_symbol(sym.IF);     }
"new"    { return new_symbol(sym.NEW);    }
"print"  { return new_symbol(sym.PRINT);  }
"read"   { return new_symbol(sym.READ);   }
"return" { return new_symbol(sym.RETURN); }
"static" { return new_symbol(sym.STATIC); }
"void"   { return new_symbol(sym.VOID);   }
"while"  { return new_symbol(sym.WHILE);  }

"="  { return new_symbol(sym.EQUAL);        }
";"  { return new_symbol(sym.SEMI);         }
","  { return new_symbol(sym.COMMA);        }
"."  { return new_symbol(sym.DOT);          }
"("  { return new_symbol(sym.LPAREN);       }
")"  { return new_symbol(sym.RPAREN);       }
"{"  { return new_symbol(sym.LBRACE);       }
"}"  { return new_symbol(sym.RBRACE);       }
"["  { return new_symbol(sym.LSQUARE);      }
"]"  { return new_symbol(sym.RSQUARE);      }
"+"  { return new_symbol(sym.PLUS);         }
"-"  { return new_symbol(sym.MINUS);        }
"*"  { return new_symbol(sym.MUL);          }
"/"  { return new_symbol(sym.DIV);          }
"%"  { return new_symbol(sym.MOD);          }
"++" { return new_symbol(sym.INC);          }
"--" { return new_symbol(sym.DEC);          }
"&&" { return new_symbol(sym.AND);          }
"||" { return new_symbol(sym.OR);           }
"==" { return new_symbol(sym.EQUALTO);      }
"!=" { return new_symbol(sym.NOTEQUALTO);   }
">"  { return new_symbol(sym.GREATER);      }
">=" { return new_symbol(sym.GREATEREQUAL); }
"<"  { return new_symbol(sym.LOWER);        }
"<=" { return new_symbol(sym.LOWEREQUAL);   }

"//"              { yybegin(COMMENT);   }
<COMMENT>.        { yybegin(COMMENT);   }
<COMMENT>"\r\n"   { yybegin(YYINITIAL); }
<COMMENT>"\n"     { yybegin(YYINITIAL); }

[0-9]+ {
  return new_symbol(sym.NUMBER, new Integer (yytext()));
}

([a-z]|[A-Z])[a-z|A-Z|0-9|_]* {
  return new_symbol(sym.IDENT, yytext());
}

"operator"(("==")|("!=")|(">")|(">=")|("<")|("<=")|("+")|("-")|("*")|("/")|("%")) {
  return new_symbol(sym.OPOVERLOAD, yytext());
}

"'"[\x20-\x7E]"'" {
  return new_symbol (sym.CHARCONST, new Character (yytext().charAt(1)));
}

. {
System.err.println("Line " + (yyline+1) + ": Lexical error ("+yytext()+").");
}